package com.hotel.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hotel.mapper.RoomMapper;
import com.hotel.pojo.Room;
import com.hotel.pojo.RoomNumber;
import com.hotel.pojo.RoomState;
import com.hotel.service.RoomService;
import com.hotel.utils.ResultInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author YanMin
 * @version 1.0
 * @description:
 * @since 2022/8/16 23:44
 */
@Service
public class RoomServiceImpl implements RoomService {
    @Autowired
    private RoomMapper roomMapper;

    //查询房间
    @Override
    public ResultInfo selectRoom(String roomId, int page, int size) {
        // pageHelper分页
        // 1、开启分页
        PageHelper.startPage(page, size);
        //2.查询
        List<Room> roomList = roomMapper.selectRoom(roomId);
        System.out.println("========" + roomList);
        // 3、把结果封装在pageInfo对象中
        PageInfo<Room> roomPageInfo = new PageInfo<>(roomList);
        System.out.println("-------------" + roomPageInfo);
        return new ResultInfo(200, "查询用户", roomPageInfo);
    }

    @Override
    public List<Map<String, Object>> selectRoomNumber() {
        List<RoomNumber> roomList = roomMapper.selectRoomNumber();
        List<Map<String, Object>> list = new ArrayList<>();
        for (RoomNumber room : roomList) {
            Map<String, Object> map = new HashMap<>();
            map.put("name", room.getRoomType());
            map.put("value", room.getCount());
            list.add(map);
        }
        return list;

    }

    @Override
    public ResultInfo selectRoomState() {
        List<RoomState> roomStateList = roomMapper.selectRoomState();
        List<Integer> integerList1 = new ArrayList<>();
        List<Integer> integerList2 = new ArrayList<>();
        for (RoomState roomState : roomStateList) {
            integerList1.add(roomState.getRoomState());
            integerList2.add(roomState.getCount2());
        }
        Map<String, Object> map = new Hashtable<>();
        map.put("integerList1", integerList1);
        map.put("integerList2", integerList2);
        return new ResultInfo(200, "pie", map);
    }


    //删除房间
    @Override
    public ResultInfo deleteRoomByRoomId(Integer roomId) {
        Integer result = roomMapper.deleteRoomByRoomId(roomId);
        if (result > 0)
            return new ResultInfo(200, "删除成功");
        return new ResultInfo(500, "删除失败");
    }

    //修改房间信息
    @Override
    public ResultInfo updateRoomByRoomId(Room room) {
        Integer result = roomMapper.updateRoomByRoomId(room);
        if (result>0)
            return new ResultInfo(200,"修改成功");
        return new ResultInfo(500,"修改失败");
    }
    //增加房间
    @Override
    public ResultInfo insertRoom(Room room) {
        Integer result = roomMapper.insertRoom(room);
        if (result>0)
            return new ResultInfo(200,"增加成功");
        return new ResultInfo(500,"增加失败");
    }

}
